// src/Service/book-information.js
import request from '@/util/request.js'

async function getBookInformation() {
    try {
        const response = await request.get('/system/bookInformation', {
            responseType: 'blob'
        });


        const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });

        // 创建临时链接并下载
        const downloadUrl = window.URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = downloadUrl;
        a.download = '图书信息.xlsx'; // 设置下载的文件名
        document.body.appendChild(a);
        a.click();

        // 清理
        window.URL.revokeObjectURL(downloadUrl);
        document.body.removeChild(a);

        return true;
    } catch (error) {
        console.error('下载失败:', error);
        alert('下载失败，请查看控制台日志');
        return false;
    }
}

export { getBookInformation }